package com.cn.por.biz.user.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.cn.por.biz.user.dao.UserDao;
import com.cn.por.biz.user.dto.ProUserDetails;
import com.cn.por.biz.user.role.dto.Role;


@Service
public class ProUserDetailsServiceImpl implements UserDetailsService {

	@Autowired
	private UserDao userDao;
	
	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		ProUserDetails user = userDao.getUserByName(username);
		if(null!=user) {
			List<Role> role = userDao.getRoleByUid(user.getId());
			user.setRoles(role);
		}
		return user;
	}

}
